Skip to content

Fix broken unit test by updating RxJS catchError operators to RxJS 7+ API#1127

Merged
renemadsen merged 3 commits intomasterfrom
copilot/fix-broken-unit-test
Oct 28, 2025
Merged

Fix broken unit test by updating RxJS catchError operators to RxJS 7+ API#1127
renemadsen merged 3 commits intomasterfrom
copilot/fix-broken-unit-test

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 22, 2025

Problem

The Angular unit tests were failing with the following errors:

TypeError: You provided an invalid object where a stream was expected. 
You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.

And:

Error: Not implemented: navigation (except hash changes)

The test download-excel-dialog.component.spec.ts was consistently failing, specifically the test case "should show error toast when download all workers fails".

Root Cause

The code was using the deprecated RxJS 6 API signature for the catchError operator:

.pipe(catchError(
  (error, caught) => {
    this.toastrService.error('Error downloading report');
    return caught;  // 'caught' is undefined in RxJS 7+
  }))

In RxJS 7+, the second parameter (caught) was removed from the catchError callback signature. When the code tried to return caught, it was actually returning undefined, which caused RxJS to throw the error "You provided an invalid object where a stream was expected".

Solution

Updated all catchError operators to use the RxJS 7+ API:

.pipe(catchError(
  (error) => {
    this.toastrService.error('Error downloading report');
    return EMPTY;  // Properly completes the observable chain
  }))

Files Changed

download-excel-dialog.component.ts

  • Fixed catchError in onDownloadExcelReport method by removing the unused caught parameter

working-hours-header.component.ts

  • Added EMPTY import from 'rxjs'
  • Fixed catchError in onDownloadExcelReport method - changed from returning caught (undefined) to EMPTY
  • Fixed catchError in onDownloadExcelReportAllWorkers method - renamed misleading parameter and changed return value to EMPTY

Impact

These changes ensure that when an error occurs during Excel report download operations, the error is properly caught, the user is notified via a toast message, and the observable chain completes gracefully. The unit tests should now pass without the invalid observable and navigation errors.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix broken unit test in angular</issue_title>
<issue_description>We get this error again and it needs to be fixed:

FAIL src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/download-excel/download-excel-dialog.component.spec.ts (7.696 s)
  ● Console

    console.error
      Error: Not implemented: navigation (except hash changes)
          at module.exports (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17)
          at navigateFetch (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/window/navigation.js:77:3)
          at exports.navigate (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/window/navigation.js:55:3)
          at Timeout._onTimeout (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/nodes/HTMLHyperlinkElementUtils-impl.js:81:7)
          at listOnTimeout (node:internal/timers:581:17)
          at processTimers (node:internal/timers:519:7) {
        type: 'not implemented'
      }

      at VirtualConsole.<anonymous> (node_modules/jest-environment-jsdom/build/index.js:63:23)

    console.error
      Error: Uncaught [TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.]
          at reportException (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
          at Timeout.task [as _onTimeout] (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js:525:9)
          at listOnTimeout (node:internal/timers:581:17)
          at processTimers (node:internal/timers:519:7) {
        detail: TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.
            at Object.createInvalidObservableTypeError (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/util/throwUnobservableError.js:5:12)
            at Object.innerFrom (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/observable/innerFrom.js:93:36)
            at /home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/operators/catchError.js:13:41
            at OperatorSubscriber._this._error (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:43:21)
            at OperatorSubscriber.Subscriber.error (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/Subscriber.js:60:18)
            at Observable.init [as _subscribe] (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/observable/throwError.js:8:58)
            at Observable._trySubscribe (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/Observable.js:41:25)
            at /home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/Observable.js:35:31
            at Object.errorContext (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
            at Observable.subscribe (/home/runner/work/eform-angular-timeplanning-plugin/eform-angular-timeplanning-plugin/eform-angular-frontend/eform-client/node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
            at...

</details>

Fixes microting/eform-angular-timeplanning-plugin#1126

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/microting/eform-angular-timeplanning-plugin/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 22, 2025 08:22
Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix broken unit test in Angular Fix broken unit test by updating RxJS catchError operators to RxJS 7+ API Oct 22, 2025
Copilot AI requested a review from renemadsen October 22, 2025 08:27
@renemadsen renemadsen marked this pull request as ready for review October 28, 2025 08:01
@renemadsen renemadsen merged commit e38d7de into master Oct 28, 2025
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants